<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: legion
  Date: 2021/10/15
  Time: 19:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表页面</title>
    <script type="text/javascript" src="/resource/js/jquery-3.2.1.js"></script>
    <link rel="stylesheet" href="/resource/css/index3.css">
</head>
<body>
<h1>列表页面</h1>
<form action="list" method="post">
    <input type="hidden" name="pageNum">
    学生姓名: <input type="text" name="name" value="${vo.name}">
    专业:<select name="id">
    <option value="">--请选择--</option>
<%--    <c:forEach items="${list}" var="m">--%>
<%--        <option value="${m.id}"  ${m.id==vo.id?'selected':''}>${m.name}</option>--%>
<%--    </c:forEach>--%>
</select>
    出生日期:<input type="date" name="dateone" value="${vo.dateone}">至
    <input type="date" name="datetwo" value="${vo.datetwo}">
    <input type="submit" value="查询">

</form>

<input type="button" value="添加" onclick="add()">
<table border="1">
    <tr>
        <td>学生姓名</td>
        <td>性别</td>
        <td>出生日期</td>
        <td>年龄</td>
        <td>联系电话</td>
        <td>专业</td>
        <td>学费</td>
        <td>住宿费</td>
        <td>报名费</td>
        <td>总计</td>
        <td>操作</td>
    </tr>
<c:forEach items="${info.list}" var="s">
    <tr>
        <td>${s.name}</td>
        <td>
            <c:if test="${s.gender==0}">
                    男
            </c:if>
            <c:if test="${s.gender==1}">
                    女
            </c:if>
        </td>
        <td>
            <fmt:formatDate value="${s.birthday}" pattern="yyyy-MM-dd"></fmt:formatDate>
        </td>
        <td>${s.age}</td>
        <td>${s.phone}</td>
        <td>${s.majorname}</td>
        <td>${s.fee}</td>
        <td>${s.accommodation}</td>
        <td>${s.applyfee}</td>
        <td>${s.applyfee+s.fee+s.applyfee}</td>
        <td><input type="button" value="修改" onclick="update(${s.id})">
            <input type="button" value="删除" onclick="del(${s.id})">
        </td>
    </tr>
</c:forEach>
<tr>
    <td colspan="20"><jsp:include page="page.jsp"></jsp:include></td>
</tr>
</table>
<script >


    $.post("getMajor",function (result) {

        console.log(result)
        for (const m in result) {
            $('[name="id"]').append('<option value="'+result[m].id+'"}>'+result[m].name+'</option>')
        }
        $('[name="id"]').val(${vo.id});
    },"json")


    
    function del(id) {

        if (confirm("确定删除?")){
            $.post("del",{id:id},function (result){
                if (result){
                    alert("删除成功")
                    location.reload();
                }else {
                    alert("删除失败")
                }
            })
        }

    }

    function add(){
        location="toAdd";
    }
    function update(id) {
        alert(id)
        location="toUpdate?id="+id;
    }

    function goPage(pageNum) {
        $('[name="pageNum"]').val(pageNum)
        $("form").submit()
    }
</script>
</body>
</html>
